#ifndef __UDP_COMMUNICATION_H__
#define __UDP_COMMUNICATION_H__

#define MAX_CLIENT_COUNT 16
#define MAX_HEART_BEAT_TIME 4

class UdpCommunication
{
public:

    UdpCommunication();
    ~UdpCommunication();

    int initServer(unsigned short port);
    int initUdpClient(char *serverIp, unsigned short serverPort);

    int getPacket(void * buffer , int len);
	void sendPacket(void * buffer , int len);
	
	void setDestAddr(const char * ip , int port)
	{
		destAddr.sin_family = AF_INET;
		destAddr.sin_port = htons(port);
		inet_aton(ip, &destAddr.sin_addr);
	}
	void getDestAddr(struct sockaddr_in & addr)
	{
		addr = destAddr;
	}

private:
	int sockfd;
	struct sockaddr_in destAddr;
	time_t lastHeartBeatTime;
	time_t clientHeartBeatTime[MAX_CLIENT_COUNT];
	struct sockaddr_in clientAddrTab[MAX_CLIENT_COUNT];
};

#endif
